package com.xy.base;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.xy.debug.LogUtils;
import com.xy.manager.MsgManager;

/**
 * Created by John on 2016/10/26.
 */

public abstract class BaseFragment extends Fragment {
    private MsgManager msgManager;
    protected View convertView;
    private SparseArray<View> mViews;

    @Override
    public void onAttach(Context context) {
        msgManager = new MsgManager(getContext());
        super.onAttach(context);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return convertView;
    }


    public View setContentView(int id) {
        return setContentView(LayoutInflater.from(getContext()).inflate(id, null, false));
    }

    public View setContentView(View view) {
        mViews = new SparseArray<>();
        convertView = view;
        return convertView;
    }

    public View getRootView() {
        return convertView;
    }

    public void showToastMsg(String str){
        if (msgManager != null){
            msgManager.showToastMsg(str);
        }else {
            LogUtils.i(str);
        }
    }

    public void showToastMsg(String str,int druation){
        msgManager.showToastMsg(str,druation);
    }

    public void showSnackMsg(String str){
        msgManager.showSnackMsg(str);
    }

    public void showSnackMsg(String str,int duration){
        msgManager.showSnackMsg(str, duration);
    }

    public void showLoading(boolean show){
        if (msgManager != null){
            msgManager.showLoading(show);
        }
    }
}
